import 'package:example/page/advance.dart';
import 'package:example/page/basic.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter ❤️ JavaScript'),
      routes: {
        '/basic': (context) => BasicPage(),
        '/jsCallNative': (context) => JsCallNativePage(),
        '/intrinsic': (context) => IntrinsicPage(),
        '/ws': (context) => WebSocketPage(),
        '/ajv': (context) => AjvPage()
      },
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
            spacing: 8,
            mainAxisAlignment: MainAxisAlignment.center,
            children: {
              '/basic': 'Basic',
              '/jsCallNative': 'JsCallNative',
              '/intrinsic': 'Intrinsic',
              '/ws': 'WebSocket',
              '/ajv': 'AJV'
            }
                .entries
                .map((e) => JumpItem(title: e.value, route: e.key))
                .toList()),
      ),
    );
  }
}

class JumpItem extends StatelessWidget {
  const JumpItem({super.key, required this.title, required this.route});

  final String title;
  final String route;

  @override
  Widget build(BuildContext context) {
    return FilledButton(
      onPressed: () {
        Navigator.of(context).pushNamed(route);
      },
      child: Text(title),
    );
  }
}
